package com.linghui.videoplus.ipai.api.http;

import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class HttpPostApi {

	public static String sendPost(String url, List<NameValuePair> params) {
		String strResult = null;
		HttpPost httpRequest = new HttpPost(url);
		/* Post运作传送变数必须用NameValuePair[]阵列储存 */
		// List<NameValuePair> params = new ArrayList<NameValuePair>();
		// params.add(new BasicNameValuePair("title", "中国"));
		try {
			httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
			HttpResponse httpResponse = new DefaultHttpClient()
					.execute(httpRequest);

			if (httpResponse.getStatusLine().getStatusCode() == 200) {
				strResult = EntityUtils.toString(httpResponse.getEntity());
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResult;
	}
}
